import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:loading_indicator/loading_indicator.dart';

import '../../pojo/Enums.dart';

class LoadingView extends StatelessWidget {

  final LoadingState state;
  final Widget child;

  const LoadingView({required this.state, required this.child, super.key});

  @override
  Widget build(BuildContext context) {
    switch (state) {
      case LoadingState.failure:
        return const Center(child: Text('加载数据失败'));
      case LoadingState.success:
        return child;
      case LoadingState.loading:
        // return const Center(child: SizedBox(height: 200, width: 200, child: CircularProgressIndicator(),));
        return Center(
          child: SizedBox(
            height: 100,
            width: 100,
            child: _buildLoadingGif(),
          ),
        );
        // return const Center(child: SizedBox(height: 200, width: 200, child: Icon(Icons.downloading, size: 200,),));
      case LoadingState.init :
        return const Text('');
    }
  }

  Widget _buildLoadingIndicator() {
    return LoadingIndicator(
      indicatorType: Indicator.lineScalePulseOut,
      colors: [Colors.grey.shade300],
      strokeWidth: 4.0,
      pathBackgroundColor: Colors.black45,
    );
  }

  Widget _buildLoadingGif() {
    return const Image(image: AssetImage("assets/img/loading.gif"), width: 60, height: 60,);
  }

}